<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">
        <i class="el-icon-caret-right"></i> 评论</el-breadcrumb-item>
    </el-breadcrumb>

    <el-divider></el-divider>
    <template>
      <el-table
          :data="tableData"
          style="width: 100%">
        <el-table-column
            prop="goodsName"
            label="书名"
            width="200"
            align="center">
        </el-table-column>
        <el-table-column
            prop="comments"
            label="评论"
            width="500"
            align="center">
        </el-table-column>
        <el-table-column label="操作" width="120" align="center">
          <template slot-scope="scope">
            <el-button type="danger" icon="el-icon-delete"circle size="mini"
                       @click="openDeleteConfirm(scope.row)"></el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>





  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      tableData: []
    }
  },
  methods: {
    //查评论信息
    listComment(){
      let url = "http://localhost:8080/comment/commentsByuId";
      axios.get(url).then((response)=>{
        this.tableData=response.data.data;
      })
    },
    handleDelete(comment){
      console.log("准备删除"+comment.id)
      let url='http://localhost:8080/comment/delete/'+comment.id;
      this.axios.post(url).then((response)=>{
        let responseBody=response.data;
        if(responseBody.state==20000){
          this.listComment();
          this.$message({
            type: 'success',
            message: '删除成功'
          });
          this.listComment();
        }else {
          this.$message({
            type: 'info',
            message: responseBody.message
          });
          this.listComment();
        }
      })
    },
    openDeleteConfirm(comment){
      let message = '此操作将永久删除【'+comment.goodsName+'】,是否继续';
      this.$confirm(message, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.handleDelete(comment);
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '删除取消'
        });
      });
    },
  },
  mounted() {
    this.listComment();
  }
}
</script>

<style scoped>

</style>